import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
/* eslint-disable @typescript-eslint/no-unused-expressions */
// 列动态弹窗
import { CpasIcon, DevGrid } from "~/public/cpas-ui";
import AntTabs from "~/public/cpas-ui/components-ui/ant-components/AntTab";
import { Input, Select, message } from "antd";
import { LoadPanel, Scrolling, Sorting } from "devextreme-react/data-grid";
import React from "react";
import { SearchOutlined } from "@ant-design/icons";
import { getDevTableData, getReportData, getReportMenu, getCorpData, } from "../../classes/HandSonGridToolService/getDataSourceService";
// import { guid } from "~/public/cpas-ui/tools/Tools";
// import DevSelect from "~/public/cpas-ui/components-ui/express-components/DevSelect";
import { createCellPos, formatDateField } from "../../../ExcelGrid/Tools";
import { getYears } from "../../../../tools/Tools";
import { dbname } from "../../classes/HandSonGridToolService/pubDbname";
import { formatNumberField } from "../../../ExcelGrid/Tools";
import { consts } from "../../../../tools/consts";
import { msgError } from "./msg";
import { SelectBox, TagBox } from "devextreme-react";
const primaryKey = "[主键]"; // 主键必须加入,否则第一列出不来,不知道什么原因
export default class ColData extends React.Component {
    newColumn1; // 用于更新dev表的新表头
    newColumn2;
    newListData1;
    newListData2;
    tabName;
    inpRef;
    inpRef2;
    defaultSrc1; //取数源默认值1
    digaoSelctOne;
    defaultVen;
    text22;
    newProps;
    constructor(props) {
        super(props);
        console.log("888---打开colData列动态弹窗属性--props", props);
        this.inpRef = React.createRef();
        this.inpRef2 = React.createRef();
        this.createRelation = this.createRelation.bind(this);
        this.AccountTabsClick = this.AccountTabsClick.bind(this);
        this.devTableDbck = this.devTableDbck.bind(this);
        this.changeInp1 = this.changeInp1.bind(this);
        this.changeInp2 = this.changeInp2.bind(this);
        this.selDataSource1 = this.selDataSource1.bind(this);
        this.selDataSource2 = this.selDataSource2.bind(this);
        this.ckData = this.ckData.bind(this);
        this.DigaoItem = this.DigaoItem.bind(this);
        this.fuzzyQuery = this.fuzzyQuery.bind(this);
        this.refresh1 = this.refresh1.bind(this);
        this.refresh2 = this.refresh2.bind(this);
        this.clearText = this.clearText.bind(this);
        this.cancelRelation = this.cancelRelation.bind(this); //取消对应关系
        this.state = {
            proName: "",
            yearSel: "",
            selSrc1: "",
            valParam1: "",
            valParam2: "",
            defaultVal: "",
            saveArr: [],
            rowVal3: "",
            cpasListData: JSON.parse(JSON.stringify(this.props.cpasData.data)),
            modifyCpasData: [],
            activeIndex: 0,
            dataSource1: "",
            dataSource2: "",
            columnsData: [],
            listData: [],
            cpasData: {},
            oneHeaders: [],
            coords: {},
            getTraslates: [],
            defLabel: "",
            getComDataSoureSelect: [],
            getDiGaoSourceSelect: [],
            getNumberSourceSelect: [],
            getYearsVal: [],
            curYear: "",
            tab2Column: [],
            tab2listData: [],
            defaultDiGaoVals: "",
            activeKeys: "底稿结构化数据",
            selectedValue: "",
            defaultV: "",
            qsyDefaultVal: "",
            getDsrc1: "",
            getcolums: [],
            qsyDefaultVal2: "",
            isShow: false,
            yearInp: "本年",
            yearInp1: "本年",
            yearInp2: "本年",
            year1: "本年",
            year2: "本年",
            projectName1: "",
            projectName2: "",
            dataSource0: "",
            fields: [],
        };
    }
    // 列动态弹窗中最上面的数据关系渲染以及存储 start 此时这里显示的是原始cpas表的行,应该取data值
    createCpasHeader(isSetState, in_saveArr) {
        if (this.props.cpasRef) {
            const currentGridData = this.props.cpasRef.getCpasTableGrid();
            //如果state.saveArr中没值,从公式中解析 add by csb 20230912 start
            if (in_saveArr) {
                this.state.saveArr.splice(0, this.state.saveArr.length); //清空
                this.state.saveArr.push(...in_saveArr); //以传入的优先
            }
            else if (this.state.saveArr.length === 0) {
                const { saveArr } = this.getColFormulaInfo();
                if (saveArr.length > 0) {
                    this.state.saveArr.push(...saveArr);
                    this.props.getTraslates(this.state.saveArr);
                    this.setState({ saveArr }); //更新状态
                }
            }
            //如果state.saveArr中没值,从公式中解析 add by csb 20230912 end
            if (this.state.saveArr.length > 0) {
                console.log("888--有公式", this.state.saveArr);
                let colData = currentGridData.data;
                //通过数据,获取modifyCpasData值,是这个[{},{}]
                const localModifyCpasData = colData.map((item) => {
                    //找到已对应的,需要获取 dataListMap
                    const oneSave = this.state.saveArr.find((aSaveValue) => aSaveValue.sourceMap === item[0]);
                    return {
                        cpasName: item[0],
                        dataListMap: oneSave ? oneSave.dataListMap : "",
                    };
                });
                if (isSetState) {
                    this.setState({ modifyCpasData: localModifyCpasData });
                }
                return localModifyCpasData;
                /* let newCpasList = [];
                const newDatas = colData.map((item, i) => {
                  let cpasReations: any = {};
                  this.state.saveArr.map((temp) => {
                    if (temp.sourceMap === item[0]) {
                      return (cpasReations = {
                        cpasName: item[0],
                        dataListMap: temp.dataListMap,
                      });
                    }
                  });
        
                  newCpasList.push(cpasReations);
                  return newCpasList;
                });
                if (isSetState) {
                  this.setState({
                    modifyCpasData: newDatas[0],
                  });
                }
        
                return newDatas[0]; */
            }
            else {
                console.log("888--无公式", this.state.saveArr);
                let colData = currentGridData.data;
                let newCpasList = [];
                const newDatas = colData.map((item, i) => {
                    let cpasReations = {};
                    cpasReations = {
                        cpasName: item[0],
                        dataListMap: "",
                    };
                    newCpasList.push(cpasReations);
                    return newCpasList;
                });
                if (isSetState) {
                    this.setState({
                        modifyCpasData: newDatas[0],
                    });
                }
                return newDatas[0];
            }
            // let colData = currentGridData.data;
            // let newCpasList = [];
            // const newDatas = colData.map((item, i) => {
            //   let cpasReations: any = {};
            //   cpasReations = {
            //     cpasName: item[0],
            //     dataListMap: "",
            //   };
            //   newCpasList.push(cpasReations);
            //   return newCpasList;
            // });
            // if (isSetState) {
            //   this.setState({
            //     modifyCpasData: newDatas[0],
            //   });
            // }
            // return newDatas[0];
        }
    }
    //存储两表关系
    createRelations() {
        this.state.modifyCpasData.map((item, index) => {
            if (index === 0) {
                return item;
            }
            else {
                if (this.state.saveArr) {
                    this.state.saveArr.map((ite) => {
                        if (item.cpasName === ite.sourceMap) {
                            return (item.dataListMap = ite.dataListMap);
                        }
                        else {
                            return "尚未对应";
                        }
                    });
                }
                return item;
            }
        });
    }
    // **************  列动态弹窗中最上面的数据关系渲染以及存储 end
    // cpas dev 关系建立：
    createRelation(sourceMap, dataListMap, cpasIndex, devIndex, dataSource0) {
        let relationArr = {};
        relationArr = {
            sourceMap: sourceMap,
            dataListMap: dataListMap,
            cpasIndex: cpasIndex,
            devIndex: devIndex,
            dataSource0: dataSource0,
        };
        return relationArr;
    }
    //切换页签
    setActiveTab(activeKey) {
        this.tabName = activeKey;
        this.setState({
            activeKeys: activeKey,
        });
        this.props.activeTab(activeKey);
    }
    // tab 页签名称
    async AccountTabsClick(activeKey) {
        try {
            /* this.tabName = activeKey;
            this.setState({
              activeKeys: activeKey,
            });
      
            this.props.activeTab(activeKey); */
            this.setActiveTab(activeKey);
            if (activeKey === "企业基础数据") {
                this.EnterpriseBaseData(); // 企业基础数据-取数源
                setTimeout(this.refresh1, 100);
            }
            if (activeKey === "底稿结构化数据") {
                this.getDiGaoOption(); // 底稿结构化数据 - 底稿名称
            }
        }
        catch (err) {
            console.error(err);
        }
    }
    /**
     * 获取公式信息
     * @returns  any
     */
    getColFormulaInfo() {
        const retData = {
            saveArr: [],
            drData: {},
        };
        if (this.newProps) {
            let colDatas = this.newProps.cpasData.header;
            let colF = this.newProps.coords.col;
            let colFormula = colDatas[colF];
            let headerFormula = colFormula.config.formula;
            if (headerFormula) {
                let params = headerFormula?.split("|||");
                let devCpasMap = params[1].slice(0, -1); // 两表关系映射
                let colDevCpasMap = JSON.parse(devCpasMap); // 反转的两表关系
                //公式数据
                let drData = JSON.parse(params[0].substr(3)); // 附加条件 和表头 fields,where
                retData.saveArr = colDevCpasMap;
                retData.drData = drData;
            }
        }
        return retData;
    }
    // 关系回显方法
    async getReviewCpasMap(cpasHeader) {
        //**** 708 */
        if (this.newProps) {
            let colDatas = this.newProps.cpasData.header;
            let colF = this.newProps.coords.col;
            let colFormula = colDatas[colF];
            let headerFormula = colFormula.config.formula;
            if (headerFormula) {
                let params = headerFormula?.split("|||");
                let devCpasMap = params[1].slice(0, -1); // 两表关系映射
                let colDevCpasMap = JSON.parse(devCpasMap); // 反转的两表关系
                //公式数据
                let drData = JSON.parse(params[0].substr(3)); // 附加条件 和表头 fields,where
                /*   if (drData.fields.includes(primaryKey)) {//删除主键
                    drData.fields.splice(drData.fields.indexOf(primaryKey), 1);
                  } */
                let updateValsCol = {};
                //映射关系
                updateValsCol.saveArr = colDevCpasMap;
                //对应关系
                // this.setState({ saveArr: rowDevCpasMap }); //重新复制这个数组,有时候没有 add by csb
                this.props.getTraslates(colDevCpasMap); //数据传给父
                if (drData.activeTab === consts.ReportTabKey) {
                    console.log("888--关系回显年度-企业", drData);
                    this.setState({
                        dataSource1: drData.dataList,
                        yearInp1: drData.dataId1 + "",
                        fields: drData.fields,
                    });
                    let result = await getYears(drData.dataId1);
                    //回显过来，打开弹窗需要执行对应参数的接口数据
                    this.interfaceQiYeListData(drData.dataList, result.toString(), dbname, [], "", "", false, 0);
                    this.interfaceQiYeHeader(drData.dataList, result.toString(), dbname, [], "", "", true, 0);
                }
                else if (drData.activeTab === consts.WpTabKey) {
                    console.log("888--关系回显年度-底稿", drData);
                    let result = await getYears(drData.dataId2);
                    //底稿结构化数据
                    await this.getDiGaoOption(drData);
                    this.setState({
                        dataSource2: drData.dataList,
                        yearInp2: drData.dataId2 + "",
                        fields: drData.fields,
                    });
                    await this.interfaceDiGaoHeader(drData.dataList, result.toString(), dbname, [], "", "", true, 0);
                    //回显过来，打开弹窗需要执行对应参数的接口数据
                    await this.interfaceDiGaoListData(drData.dataList, result.toString(), dbname, [], "", "", false, 0);
                    // 年度字段
                    // updateValsCol.yearInp = drData.dataId; //年度汉字标识,并不是2021这样的
                }
                // this.setState(updateValsCol); //更新值
                //先暂时注销，备用
                // cpasHeader?.map((item: any) => {
                //   colDevCpasMap.map((ite: any) => {
                //     if (ite.sourceMap === item.cpasName) {
                //       item.dataListMap = ite.dataListMap;
                //     }
                //     return ite;
                //   });
                //   return item;
                // });
                // this.setState({
                //   modifyCpasData: cpasHeader,
                // });
                console.log("888---colDevCpasMap", colDevCpasMap);
                this.setState({
                    saveArr: colDevCpasMap,
                });
                let ary = colDevCpasMap.map((item, i) => {
                    return item.dataSource0;
                });
                var nary = ary.sort();
                for (var i = 0; i < nary.length - 1; i++) {
                    if (nary[i] === nary[i + 1]) {
                        console.log("888--是同一个表" + nary[i]);
                        cpasHeader?.map((item) => {
                            colDevCpasMap.map((ite) => {
                                if (ite.sourceMap === item.cpasName) {
                                    item.dataListMap = ite.dataListMap;
                                }
                                return ite;
                            });
                            return item;
                        });
                        /*  by csb 20230921
                           this.setState({
                              modifyCpasData: cpasHeader,
                            }); */
                    }
                    else {
                        console.log("888---不是同一张表不能建立关系");
                    }
                }
                this.setActiveTab(drData.activeTab); //切换到公式定义的页
                return { params0: drData, colDevCpasMap };
            }
            else {
                cpasHeader.forEach((item) => {
                    item.dataListMap = "";
                });
                this.setState({
                    dataSource1: this.state.qsyDefaultVal,
                    yearInp1: "本年",
                    saveArr: [],
                    fields: [],
                });
            }
        }
        /* by csb 20230921
        this.setState({ modifyCpasData: cpasHeader });
         */
    }
    // 上面动态弹窗 数据点击交互事件,
    //  const [changeIndex,setChangeIndex] = useState(0);
    ckData(e, index, item) {
        this.setState({
            rowVal3: item.cpasName,
            activeIndex: index,
        });
    }
    //取消对应
    cancelRelation(e, index, item) {
        e.stopPropagation(); //阻止事件冒泡
        console.log("888---cancelRelation", e, index, item);
        //删除数组中对应元素
        let curIndex = this.state.saveArr.findIndex((findItem) => findItem.dataListMap == item.dataListMap);
        if (curIndex > -1) {
            this.state.saveArr.splice(curIndex, 1);
        }
        console.log("888--saveArr", this.state.saveArr);
        this.createCpasHeader(true, JSON.parse(JSON.stringify(this.state.saveArr))); //传入saveArr add by csb 20230921
        // 把建立的两表关系传给父组件
        this.props.getTraslates(this.state.saveArr);
    }
    // 点击列，拿到当前列值,并创建关联关系进行保存
    devTableDbck(e) {
        console.log("888--this.state.datasoruce0", this.state.dataSource0, this.state.saveArr);
        //查找是否有对应的,存在的删除 add by csb
        let findIndex = this.state.saveArr.findIndex((item) => item.sourceMap === this.state.rowVal3);
        if (findIndex > -1) {
            this.state.saveArr.splice(findIndex, 1);
        }
        if (this.state.saveArr.length > 0) {
            let ss = this.state.saveArr.findIndex((item) => item.dataSource0 === this.state.dataSource0);
            if (ss < 0) {
                console.log("888--不是同一个表的数据，不保存");
                message.open({
                    type: "warning",
                    content: " 不是同一张表的数据，不能建立关系 ",
                    className: "custom-class",
                    style: {
                        marginTop: "20vh",
                    },
                });
                this.setState({
                    saveArr: [],
                });
            }
            else {
                console.log("888--说明是同一张表中的数据,就保存起来");
                // 建立关系
                const result = this.createRelation(this.state.rowVal3, e.values[0], this.state.activeIndex, e.row.dataIndex, this.state.dataSource0); //relationArr --e.values[0】dev表行名
                this.state.saveArr.push(result); // 把每次点击建立的关系保存到数组中
            }
            console.log("888---ss", ss);
        }
        else {
            // 建立关系
            const result = this.createRelation(this.state.rowVal3, e.values[0], this.state.activeIndex, e.row.dataIndex, this.state.dataSource0); //relationArr --e.values[0】dev表行名
            this.state.saveArr.push(result); // 把每次点击建立的关系保存到数组中
        }
        // // 建立关系
        // const result = this.createRelation(
        //   this.state.rowVal3,
        //   e.values[0],
        //   this.state.activeIndex,
        //   e.row.dataIndex,
        //   this.state.dataSource0
        // ); //relationArr --e.values[0】dev表行名
        // this.state.saveArr.push(result); // 把每次点击建立的关系保存到数组中
        // this.createCpasHeader(true);
        // 第一步：属性传值的方式传给父亲--两表建立关系
        this.props.getTraslates(this.state.saveArr);
        let devHeader = e.data;
        let devHeaders = Object.keys(devHeader);
        // 转化参数格式
        let dd = devHeaders.map((item) => {
            let items = `${"[" + item + "]"}`;
            return items;
        });
        this.props.getcolums(dd);
        this.createRelations(); // 存储两表关系
        this.forceUpdate(); // 双击有时不显示
    }
    //******** 检索条件接口调用 start */
    //企业基础数据 -- 取数源  {"dmName": "base.reportItems","dataSrcName": "报表项目基础数据"}
    async EnterpriseBaseData() {
        let data = await getCorpData();
        this.defaultVen = data[0].dataSrcName;
        this.setState({
            dataSource1: data[0].dmName,
            dataSource0: data[0].dmName, //英文名
        });
        // 需要转化一下格式
        const transferData = data.map((item) => {
            return { label: item.dataSrcName, value: item.dmName };
        });
        this.setState({
            getComDataSoureSelect: transferData,
            qsyDefaultVal: transferData[0].value, // 默认显示第一个值
        });
        this.props.getDsrc1(transferData[0].value);
        this.props.getTbname1(transferData[0].value);
        // 1自动执行接口，this.state.getComDataSoureSelect[0].dmName // 由于我的机子2023年没有数据，所以需要改写一下 2017
        const result = await getYears("本年");
        this.interfaceQiYeListData(transferData[0].value, result.toString(), dbname, [], "", "", false, 0);
        this.interfaceQiYeHeader(transferData[0].value, result.toString(), dbname, [], "", "", true, 0);
    }
    // 底稿结构化数据 -- 底稿名称列表 接口拿数据
    async getDiGaoOption(drData) {
        const newDrData = (drData || {});
        //报表项目,以公式定义的优先
        const itemName = newDrData.displayReportItem || this.props.itemName;
        let data = await getReportMenu();
        let uniqueData = data.reduce((acc, curr) => {
            if (acc.findIndex((item) => item.ReportItem === curr.ReportItem) === -1) {
                acc.push(curr);
            }
            return acc;
        }, []);
        // 转化数据格式，展示下拉框
        if (data.length > 0) {
            const transferData = uniqueData.map((item) => {
                return { label: item.ReportItem, value: item.ReportItem };
            });
            this.setState({
                getDiGaoSourceSelect: transferData,
                selectedValue: transferData[0].value,
            });
            this.digaoSelctOne = transferData[0].value;
            //如果存在传入的项目名称,底稿名称下拉框要默认对应上去
            if (transferData.some((item) => item.label === itemName)) {
                this.digaoSelctOne = itemName;
            }
            await this.DigaoItem(this.digaoSelctOne, newDrData); // 底稿名称默认有值的时候，取数源下拉数据也要默认有的，但是不选中
            // // this.DigaoItem(this.digaoSelctOne); // 底稿名称默认有值的时候，取数源下拉数据也要默认有的，也要选中
            // // 此代码有用，后期再测试功能 当itemName存在时，底稿名称下拉框要默认对应上去
            // if ((this.tabName = "底稿结构化数据" && this.props.itemName)) {
            //   // 左边树节点点击拿到的报表项目名称和底稿名称对应在上去。就默认出来
            //   transferData.filter((item) => {
            //     if (item.label === this.props.itemName) {
            //       this.setState({
            //         selectedValue: this.props.itemName,
            //       });
            //     } else {
            //       this.setState({
            //         selectedValue: transferData[0].value,
            //       });
            //     }
            //   });
            // } else {
            //   this.setState({
            //     selectedValue: transferData[0].value,
            //   });
            // }
        }
    }
    //******** 检索条件接口调用 end */
    // tab1--取数源 下拉框 取值
    async selDataSource1(val, item) {
        try {
            this.props.getDsrc1(val);
            this.props.getTbname1(val);
            this.setState({
                dataSource1: val,
                defaultVal: item.label,
                defLabel: item.value,
                dataSource0: val,
            });
            let result = await getYears("本年");
            this.interfaceQiYeListData(val, this.state.valParam1 ? this.state.valParam1 : result.toString(), dbname, [], "", "", false, 0);
            this.interfaceQiYeHeader(val, this.state.valParam1 ? this.state.valParam1 : result.toString(), dbname, [], "", "", true, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    // tab2-底稿-取数源 下拉框 取值-
    async selDataSource2(val, item) {
        try {
            this.props.getDsrc1(val);
            this.props.getTbname2(val);
            this.setState({
                dataSource2: val,
                defaultVal: item.label,
                defLabel: item.value,
                dataSource0: val,
            });
            let result = await getYears("本年");
            await this.interfaceDiGaoHeader(val, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", true, 0);
            await this.interfaceDiGaoListData(val, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", false, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    // 底稿结构化数据 - 底稿名称 触发事件
    async DigaoItem(itemName, drData) {
        const newDrData = (drData || {});
        try {
            this.setState({ selectedValue: itemName });
            let data = await getReportData(itemName);
            if (data.length === 0)
                return msgError("报表项目找不到子项:" + itemName);
            let curDmName = ""; //当前的api接口
            const items = data.map((item) => {
                //借用一下,如果找到api名称,赋值
                if (item.dmName === newDrData.dataList) {
                    curDmName = item.dmName;
                }
                return { label: item.dataSrcName, value: item.dmName };
            });
            curDmName = curDmName || items[0].value;
            if (items) {
                this.setState({
                    getNumberSourceSelect: items,
                    qsyDefaultVal2: curDmName,
                    dataSource2: curDmName,
                });
            }
            //找到当前项目传给父组件,干啥用呢?
            let curItemList = items.filter((item) => item.value === curDmName);
            this.props.getDsrc1(curItemList.length > 0 ? curItemList[0].value : items[0].value);
            console.log("888--curItemList", curItemList, items[0]);
            // this.props.getDsrc1(items[0].value);
            this.props.getTbname2(items[0].value);
            // 底稿结构化数据  默认打开页面的时候 接口自执行
            const result = await getYears("本年");
            await this.interfaceDiGaoHeader(items[0].value, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", true, 0);
            await this.interfaceDiGaoListData(items[0].value, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", false, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    //年度-触发年度下拉框取出值
    // 新的 UI库组件
    async selYear1(val) {
        try {
            const result = await getYears(val.value);
            this.props.getYearVal(val.value); // 属性传值
            this.props.getYearSel1(val.value);
            this.setState({
                valParam1: result.toString(), // 触发年度改变
            });
            this.interfaceQiYeListData(this.state.dataSource1
                ? this.state.dataSource1
                : this.state.qsyDefaultVal, result.toString(), dbname, [], "", "", false, 0);
            this.interfaceQiYeHeader(this.state.dataSource1
                ? this.state.dataSource1
                : this.state.qsyDefaultVal, result.toString(), dbname, [], "", "", true, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    async selYear2(val) {
        try {
            const result = await getYears(val.value);
            this.props.getYearVal(val.value);
            this.props.getYearSel2(val.value);
            this.setState({
                valParam2: result.toString(),
            });
            await this.interfaceDiGaoHeader(this.state.dataSource2
                ? this.state.dataSource2
                : this.state.qsyDefaultVal2, result.toString(), dbname, [], "", "", true, 0);
            await this.interfaceDiGaoListData(this.state.dataSource2
                ? this.state.dataSource2
                : this.state.qsyDefaultVal2, result.toString(), dbname, [], "", "", false, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    // // 封装的模糊检索方法
    // fuzzyQuery(list, keyWord) {
    //   var arr = [];
    //   for (var i = 0; i < list.length; i++) {
    //     if (list[i].项目 && list[i].项目.indexOf(keyWord) >= 0) {
    //       arr.push(list[i]);
    //     }
    //     if (list[i].项目名称 && list[i].项目名称.indexOf(keyWord) >= 0) {
    //       arr.push(list[i]);
    //     }
    //   }
    //   return arr;
    // }
    // 封装的模糊检索方法 -- 2023.7.10 下午14:45 邵宏和我定的按‘主键’搜索
    fuzzyQuery(list, keyWord) {
        var arr = [];
        for (var i = 0; i < list.length; i++) {
            if (list[i].主键 && list[i].主键.indexOf(keyWord) >= 0) {
                arr.push(list[i]);
            }
        }
        return arr;
    }
    // 项目名称
    async changeInp1(e) {
        try {
            this.setState({
                proName: this.inpRef.current.input.value,
                projectName1: e.target.value,
            });
            this.props.getProjectName1(e.target.value);
            let result = await getYears("本年");
            this.interfaceQiYeListData(this.state.dataSource1
                ? this.state.dataSource1
                : this.state.qsyDefaultVal, this.state.valParam1 ? this.state.valParam1 : result.toString(), dbname, [], "", "", false, 0);
            this.interfaceQiYeHeader(this.state.dataSource1
                ? this.state.dataSource1
                : this.state.qsyDefaultVal, this.state.valParam1 ? this.state.valParam1 : result.toString(), dbname, [], "", "", true, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    async changeInp2(e) {
        try {
            this.setState({
                proName: this.inpRef2.current.input.value,
                projectName2: e.target.value,
            });
            this.props.getProjectName2(e.target.value);
            let result = await getYears("本年");
            await this.interfaceDiGaoHeader(this.state.dataSource2
                ? this.state.dataSource2
                : this.state.qsyDefaultVal2, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", true, 0);
            await this.interfaceDiGaoListData(this.state.dataSource2
                ? this.state.dataSource2
                : this.state.qsyDefaultVal2, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", false, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    async refresh1() {
        // 刷新一遍接口
        //检索条件保留不变，去进行刷新
        try {
            let result = await getYears("本年");
            // 刷新一遍接口
            this.interfaceQiYeListData(this.state.dataSource1
                ? this.state.dataSource1
                : this.state.qsyDefaultVal, this.state.valParam1 ? this.state.valParam1 : result.toString(), dbname, [], "", "", false, 0);
            this.interfaceQiYeHeader(this.state.dataSource1
                ? this.state.dataSource1
                : this.state.qsyDefaultVal, this.state.valParam1 ? this.state.valParam1 : result.toString(), dbname, [], "", "", true, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    async refresh2() {
        try {
            let result = await getYears("本年");
            await this.interfaceDiGaoHeader(this.state.dataSource2
                ? this.state.dataSource2
                : this.state.qsyDefaultVal2, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", true, 0);
            await this.interfaceDiGaoListData(this.state.dataSource2
                ? this.state.dataSource2
                : this.state.qsyDefaultVal2, this.state.valParam2 ? this.state.valParam2 : result.toString(), dbname, [], "", "", false, 0);
        }
        catch (err) {
            console.error(err);
        }
    }
    clearText = (index) => {
        const { modifyCpasData } = this.state;
        const newDataList = [...modifyCpasData];
        newDataList[index].dataListMap = "";
        this.setState({ modifyCpasData: newDataList });
    };
    //界面回显示的初始化参数
    getInitParams = () => {
        return {
            components: [],
            saveArr: [],
            // singleValueGroup: [],
            // sortVal: "",
            value1: "",
            text2: "",
            chgItem: "",
        };
    };
    /**
     * 返回公式数据
     * @returns DrcData
     */
    getDcDataResult() {
        if (!this.state.fields.includes(primaryKey) &&
            this.state.columnsData.some((item) => "[" + item.dataField + "]" === primaryKey)) {
            this.state.fields.unshift(primaryKey);
            this.setState({ fields: this.state.fields });
        }
        const newFields = this.state.columnsData
            .filter((item) => this.state.fields.includes("[" + item.dataField + "]"))
            .map((item2) => "[" + item2.dataField + "]");
        //如果只有主键,为[]
        if (newFields.length === 1 && newFields[0] === primaryKey) {
            newFields.splice(0, newFields.length); // 清空
        }
        let orderStr = "case [主键] ";
        const whereArr = this.state.saveArr.map((item, index) => {
            orderStr += ` when '${item.dataListMap}' then  ${index} `;
            return `'${item.dataListMap}'`;
        });
        orderStr += " else 9999 end ";
        const whereStr = primaryKey + " in (" + whereArr.join(",") + ")";
        //this.state.saveArr
        return {
            activeTab: this.state.activeKeys,
            // dbName: state.dbName,  // 为了模板，去掉，6.21 去掉dbname,前端不再传
            // dataList: state.rowSrc2.value, // 取数源 表名 "fa.getList" this.state.dataList ComDataSoureSelect
            dataId: this.state.yearInp,
            dataId1: this.state.yearInp1,
            dataId2: this.state.yearInp2,
            fields: newFields,
            where: whereStr,
            order: orderStr,
            top: 0,
            displayReportItem: this.state.selectedValue,
            displayFilters: "", ///显示用到的条件, 计算
        };
    }
    // 企业基础数据
    async interfaceQiYeListData(tname, data_id, dbName, fields, where, order, queryMeta, top) {
        try {
            let ab = await this.getDevListData_popRow(tname, data_id, dbName, fields, where, order, queryMeta, top);
            if (ab) {
                // formatNumberField(ab.columnDas);
                // this.newColumn1 = ab.columnDas;
                this.newListData1 = ab.devTableList;
                //模糊检索
                if (this.inpRef.current) {
                    let filterListData = this.fuzzyQuery(this.newListData1, this.inpRef.current.input.value);
                    this.newListData1 = filterListData;
                    if (this.inpRef.current.input.value === "") {
                        this.newListData1 = ab.devTableList;
                    }
                }
                this.forceUpdate();
            }
            else {
                // this.newColumn1 = [];
                this.newListData1 = [];
                this.forceUpdate();
            }
        }
        catch (err) {
            console.error(err);
        }
    }
    // 企业基础数据 -- 拿表头数据类型
    async interfaceQiYeHeader(tname, data_id, dbName, fields, where, order, queryMeta, top) {
        let res = await this.getDevListData_dataTYpe(tname, data_id, dbName, fields, where, order, queryMeta, top);
        if (res && res.columnData) {
            formatNumberField(res.columnData);
            this.setState({ columnsData: res.columnData }); //add by csb 20230921加列数据源
            this.newColumn1 = res.columnData;
            this.forceUpdate();
        }
    }
    // 底稿结构化数据
    async interfaceDiGaoListData(tname, data_id, dbName, fields, where, order, queryMeta, top) {
        this.newListData2 = [];
        this.forceUpdate();
        try {
            let ab = await this.getDevListData_popRow(tname, data_id, dbName, fields, where, order, queryMeta, top);
            if (ab) {
                formatDateField(ab.devTableList);
                this.newListData2 = ab.devTableList;
                //模糊检索
                let filterListData = this.fuzzyQuery(this.newListData2, this.inpRef2.current.input.value);
                this.newListData2 = filterListData;
                if (this.inpRef2.current.input.value === "") {
                    this.newListData2 = ab.devTableList;
                }
                this.forceUpdate();
            }
            else {
                // this.newColumn2 = [];
                this.newListData2 = [];
                this.forceUpdate();
            }
        }
        catch (err) {
            console.error(err);
        }
    }
    //底稿结构化表头
    async interfaceDiGaoHeader(tname, data_id, dbName, fields, where, order, queryMeta, top) {
        // 拿表头数据类型
        let res = await this.getDevListData_dataTYpe(tname, data_id, dbName, fields, where, order, queryMeta, top);
        if (res && res.columnData) {
            formatNumberField(res.columnData);
            this.setState({ columnsData: res.columnData }); //add by csb 20230921加列数据源
            this.newColumn2 = res.columnData;
            this.forceUpdate();
        }
    }
    // 接口调用
    async getDevListData_popRow(dbName, tname, data_id, fields, where, order, queryMeta, top) {
        let devTableList = [];
        // const columnDas: any = [];
        devTableList = await getDevTableData(dbName, tname, data_id, fields, where, order, queryMeta, 0);
        return { devTableList };
    }
    // 接口调用-针对添加数据类型
    async getDevListData_dataTYpe(dbName, tname, data_id, fields, where, order, queryMeta, top) {
        let devTableListType = [];
        devTableListType = await getDevTableData(dbName, tname, data_id, fields, where, order, true, 0);
        let columnData = [];
        devTableListType.map((item) => {
            columnData.push({
                dataField: item.FieldName,
                caption: item.FieldCaption,
                fixed: false,
                minWidth: "160px",
                // width: "300px",
                // maxWidth: "300px",
                FieldType: item.FieldType,
            });
            return item;
        });
        if (columnData.length > 0) {
            columnData[0].fixed = true; // 冻结主键第一列
        }
        this.forceUpdate();
        return { devTableListType, columnData };
    }
    componentDidUpdate(prevProps, prevState, snapshot) {
        //如果是界面显示时执行
        if (this.props.isShowColForm) {
            this.props.setIsShowColForm(false); //设置为false
            //没有公式
            if (!this.props.existsColFormula) {
                console.log("888---componentDidUpdate 无公式", this.props.existsColFormula);
                this.componentDidMount(); //每次都需要调用
                //不存在公式的,先要清除对应关系
                this.state.saveArr.forEach((item) => (item.sourceMap = ""));
                this.createCpasHeader(true); // 自动获取原始cpas表的数据
                let updateValues = this.getInitParams();
                this.setState(updateValues); //初始化这些值界面参数值
            }
            else {
                //有公式
                console.log("888--有公式", this.state.saveArr);
                this.newProps = this.props; //关系回显需要
                let cpasHeader = this.createCpasHeader(true); // 自动获取原始cpas表的数据
                console.log("888--cpasHeader-didupdate", cpasHeader);
                //关系回显,这个方法中会调用  this.getDiGaoOption(); // 底稿结构化数据 - 底稿名称
                this.getReviewCpasMap(cpasHeader); //关系回显,这个方法中会调用
            }
        }
    }
    async componentDidMount() {
        // this.tabName = "企业基础数据";
        this.tabName = consts.ReportTabKey;
        this.EnterpriseBaseData(); // 企业基础数据-取数源
        // this.createCpasHeader(); // 自动获取原始cpas表的数据
        this.getDiGaoOption(); // 底稿结构化数据 - 底稿名称
        getReportData(this.digaoSelctOne); // 底稿结构化数据--取数源列表
        //本年 传参到定义公式
        this.props.getYearVal("本年");
        this.setState({
            valParam1: (await getYears("本年")) + "",
        });
        this.AccountTabsClick("底稿结构化数据");
    }
    componentWillReceiveProps(nextProps) {
        this.newProps = nextProps;
        if (this.props.cpasRef) {
            const currentGridData = this.props.cpasRef.getCpasTableGrid();
            let colData = currentGridData.data;
            const newDatas = colData.map((item) => {
                let cpasReation = null;
                for (let j = 0; j < this.state.saveArr.length; j++) {
                    const save = this.state.saveArr[j];
                    if (save.sourceMap === item[0]) {
                        cpasReation = { cpasName: item[0], dataListMap: save.dataListMap };
                    }
                }
                if (cpasReation === null) {
                    return {
                        cpasName: item[0],
                        dataListMap: "",
                    };
                }
                else {
                    return cpasReation;
                }
            });
            /* by csb 20230921
             this.setState({
               modifyCpasData: [...newDatas],
             }); */
        }
        // 列动态公式回显问题，有公式就回显，无公式就不回显,回显还要加上取数源表名和年度
        // if (nextProps.reviewCpasMap) {
        //   if (nextProps.reviewCpasMap.length === 0) {
        //     // 点击的不是母列
        //     this.state.modifyCpasData.map((item) => {
        //       item.dataListMap = "";
        //       return item;
        //     });
        //   } else {
        //     // 点击的是母列
        //     this.state.modifyCpasData?.map((item: any) => {
        //       nextProps.reviewCpasMap.map((ite: any) => {
        //         if (ite.sourceMap === item.cpasName) {
        //           item.dataListMap = ite.dataListMap;
        //         }
        //         return item;
        //       });
        //       return item;
        //     });
        //   }
        // }
    }
    /**
     * 获取缩放比例,程序设计按1366来设计
     * @returns  number
     */
    getWindowZoomRate() {
        return window.innerWidth / 1366;
    }
    /**
     * 获取缩放比例后的实际宽度
     */
    getZoomScale(value) {
        return value * this.getWindowZoomRate();
    }
    /**
     * tabBox组件下载渲染样式(字符数据方式)
     * 注意属性设置 maxDisplayedTags: 1,
     */
    tabBoxOnMultiTagPreparingOfStrArray(args) {
        const selectedItemsLength = args.selectedItems.length;
        if (selectedItemsLength > 0) {
            if (typeof args.selectedItems[0] &&
                args.selectedItems[0].hasOwnProperty("id")) {
                ///如果是对象排序
                args.selectedItems.sort((a, b) => a.id.localeCompare(b.id));
            }
            let value = args.selectedItems[0];
            //如果是对象
            if (typeof value == "object") {
                if (value.text) {
                    value = value.text;
                }
                else if (value.name) {
                    value = value.name;
                }
            }
            args.text = `${value} 等${selectedItemsLength}项`;
        }
        else {
            args.cancel = true;
        }
    }
    render() {
        return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "box_bg", children: [this.state.isShow ? _jsx("div", { className: "overlay_relates" }) : null, _jsx("div", { className: "box_flex_col mb-24 ", children: this.state.modifyCpasData.map((item, index) => {
                                return index === 0 ? null : (_jsx("div", { onClick: (e) => this.ckData(e, index, item), children: _jsxs("div", { className: "box_flex_row cur" +
                                            (this.state.activeIndex === index ? " bd_active" : ""), children: [_jsx("div", { className: "diamond", children: createCellPos(index) }), _jsxs("div", { className: "flex_col small_bg", children: [_jsx("div", { className: "f1", children: item.cpasName }), _jsx("div", { children: item.dataListMap ? (_jsxs("span", { children: [_jsx("span", { children: item.dataListMap }), _jsx("span", { title: "\u53D6\u6D88\u5BF9\u5E94", style: { cursor: "pointer" }, onClick: (e) => this.cancelRelation(e, index, item), children: _jsx(CpasIcon, { style: { marginLeft: 10 }, type: "icon-close", color: "red" }) })] })) : (_jsx("span", { style: { color: "red" }, children: "\u5C1A\u672A\u5BF9\u5E94" })) })] })] }) }, index));
                            }) })] }), _jsx("div", { className: "con", children: _jsxs(AntTabs, { tabBarStyle: { background: "#FFF" }, activeKey: this.state.activeKeys, onChange: this.AccountTabsClick, children: [_jsx(AntTabs.Panel, { tab: consts.ReportTabKey, style: { marginTop: "5px" }, children: _jsxs("div", { children: [_jsxs("div", { className: "flexCon mb-10 f12", children: [_jsxs("div", { className: "flex-start", children: [_jsx("div", { className: "mr-8", children: "\u53D6\u6570\u6E90:" }), _jsx("div", { className: "mr-24", id: "self_sty", children: _jsx(Select, { defaultValue: this.state.dataSource1, value: this.state.dataSource1, 
                                                                // value={this.defaultVen}
                                                                // style={{ width: 180 }}
                                                                options: this.state.getComDataSoureSelect, onChange: this.selDataSource1 }) }), _jsx("div", { className: "mr-8", children: "\u5E74\u5EA6:" }), _jsx("div", { className: "custom_curYear", children: _jsx(SelectBox, { width: 95, dataSource: consts.YearTagList, value: this.state.yearInp1, onValueChanged: (val) => {
                                                                    this.setState({ yearInp1: val.value });
                                                                    this.selYear1(val);
                                                                } }) })] }), _jsxs("div", { className: "flex-start", children: [_jsx("div", { className: "mr-8", children: "\u9879\u76EE\u540D\u79F0:" }), _jsx("div", { children: _jsx(Input, { style: { height: "30px" }, ref: this.inpRef, size: "small", onPressEnter: this.changeInp1, defaultValue: this.state.projectName1, suffix: _jsx(SearchOutlined, { onClick: this.changeInp1 }) }) }), _jsx("div", { className: "icon_refresh", onClick: this.refresh1, children: _jsx(CpasIcon, { type: "icon-yuefenzhongzhi" }) })] })] }), _jsx("div", { className: "h200", children: _jsxs(DevGrid.RangeTap, { dataSource: this.newListData1, defaultColumns: this.newColumn1, columns: this.newColumn1, showBorders: true, showRowLines: true, onCellDblClick: this.devTableDbck, columnMinWidth: 120, columnAutoWidth: true, rtlEnabled: false, children: [_jsx(Sorting, { mode: "none" }), _jsx(Scrolling, { mode: "infinite" }), _jsx(LoadPanel, { enabled: false })] }) })] }) }, consts.ReportTabKey), _jsx(AntTabs.Panel, { tab: consts.WpTabKey, style: { marginTop: "5px" }, children: _jsxs("div", { children: [_jsx("div", { style: { overflow: "auto", width: "100%" }, children: _jsxs("div", { className: "flexCon mb-10 f12", children: [_jsxs("div", { className: "flex-start", children: [_jsx("div", { className: "mr-8 nowrap", children: "\u5E95\u7A3F\u540D\u79F0:" }), _jsx("div", { className: "mr-8 custom_sel", id: "self_sty", children: _jsx(SelectBox, { placeholder: "\u9009\u62E9\u5E95\u7A3F\u540D\u79F0", noDataText: "\u65E0\u6570\u636E", searchEnabled: true, displayExpr: "label", valueExpr: "value", dataSource: this.state.getDiGaoSourceSelect, defaultValue: this.state.selectedValue, value: this.state.selectedValue, onItemClick: (e) => {
                                                                        this.DigaoItem(e.itemData.value);
                                                                    }, dropDownOptions: { width: "300px" } }) }), _jsx("div", { className: "mr-8 nowrap", children: "\u53D6\u6570\u6E90:" }), _jsx("div", { className: "mr-8 custom_sel", id: "self_sty", children: _jsx(Select, { defaultValue: this.state.dataSource2, value: this.state.dataSource2, style: { width: 160 }, options: this.state.getNumberSourceSelect, onChange: this.selDataSource2 }) }), _jsx("div", { className: "mr-8 nowrap", children: "\u5E74\u5EA6:" }), _jsx("div", { className: "custom_sel custom_curYear", children: _jsx(SelectBox, { width: 95, dataSource: consts.YearTagList, value: this.state.yearInp2, onValueChanged: (val) => {
                                                                        this.setState({ yearInp2: val.value });
                                                                        this.selYear2(val);
                                                                    } }) })] }), _jsxs("div", { className: "flex-start", children: [_jsx("div", { className: "mr-8 nowrap", children: "\u9700\u8981\u7684\u5217:" }), _jsx("div", { children: _jsx(TagBox, { width: this.getZoomScale(150), items: this.state.columnsData
                                                                        .filter((item) => "[" + item.dataField + "]" !== primaryKey)
                                                                        .map((item) => {
                                                                        return {
                                                                            value: `[${item.dataField}]`,
                                                                            text: item.dataField,
                                                                        };
                                                                    }), value: this.state.fields, valueExpr: "value", displayExpr: "text", onValueChanged: (e) => this.setState({ fields: e.value }), searchEnabled: true, multiline: false, showSelectionControls: true, applyValueMode: "useButtons", maxDisplayedTags: 1, onMultiTagPreparing: this.tabBoxOnMultiTagPreparingOfStrArray, noDataText: "\u6CA1\u6709\u5217", dropDownOptions: {
                                                                        minWidth: 200,
                                                                        width: this.getZoomScale(300),
                                                                    } }) })] }), _jsxs("div", { className: "flex-start", children: [_jsx("div", { className: "mr-8 nowrap", children: "\u9879\u76EE\u540D\u79F0:" }), _jsx("div", { children: _jsx(Input, { style: {
                                                                        height: "30px",
                                                                        width: this.getZoomScale(150),
                                                                    }, ref: this.inpRef2, size: "small", 
                                                                    // onChange={this.changeInp2}
                                                                    onPressEnter: this.changeInp2, defaultValue: this.state.projectName2, suffix: _jsx(SearchOutlined, { onClick: this.changeInp2 }) }) }), _jsx("div", { className: "icon_refresh", onClick: this.refresh2, children: _jsx(CpasIcon, { type: "icon-yuefenzhongzhi" }) })] })] }) }), _jsx("div", { className: "h200", children: _jsxs(DevGrid.RangeTap, { height: 200, dataSource: this.newListData2, defaultColumns: this.newColumn2, columns: this.newColumn2, showBorders: true, showRowLines: true, showColumnLines: true, rowAlternationEnabled: false, onCellDblClick: this.devTableDbck, columnMinWidth: 120, columnAutoWidth: true, rtlEnabled: false, children: [_jsx(Sorting, { mode: "none" }), _jsx(Scrolling, { mode: "infinite" }), _jsx(LoadPanel, { enabled: false })] }) })] }) }, consts.WpTabKey)] }) })] }));
    }
}
